<template>
  <div class="loginbody">
    <div style="text-align: center;"> <img  style="width: 200px; height: 200px" src="../assets/images/anhui-nongye.png"  /></div>
    <div class="logindata">
      <div class="logintext">
        <h3>农业面源污染监测系统</h3>
      </div>
      <div>
        <el-form>
          <el-form-item>
            <el-input
              v-model="loginData.username"
              clearable
              placeholder="请输入账号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="loginData.password"
              clearable
              placeholder="请输入密码"
              show-password
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <!-- <div class="tool">
        <div>
          <el-checkbox v-model="checked" @change="remenber"
            >记住密码</el-checkbox
          >
        </div>
        <div>
          <span class="shou" @click="forgetpas">忘记密码？</span>
        </div>
      </div> -->
      <div style=" margin-top: 10px;text-align: center;">
        <el-button style="width: 100%;" type="primary" @click="btnLogin()">登录</el-button>
        
      </div>
      <div style=" margin-top: 10px;text-align: center;">
        <el-button style="width: 100%;"  @click="registerBtn()">注册</el-button>
      </div>

    </div>
  </div>
</template>

<script setup>
import * as userApi from "@/api/userApi";
import { reactive, ref, onMounted, inject } from "vue";
import { storeToRefs } from 'pinia'
import { useCounterStore } from '@/stores/counter'
const store = useCounterStore()

import { useRouter } from "vue-router";
const router = useRouter();

const username = ref("");
const password = ref("");
const errorMessage = ref("");
const checked = ref("");
const remenber = ref("");
const register = ref("");


const loginData = reactive({
  username: "admin",
  password: "",
});

function btnLogin() {
  userApi.login(loginData).then((response) => {
    if (response.data.code == 200) {
      store.setToken(response.data.data.token);
      store.username = response.data.data.username;
      store.id = response.data.data.id;
      store.uType = response.data.data.uType;
      router.push("/navigation");
    }
  });
}

function registerBtn(){
  router.push("/register");
}
</script>

<style scoped>
.loginbody {
  width: 100%;
  height: 100%;
  min-width: 1000px;
  background-image: url("@/assets/images/login-2.jpg");
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  background-repeat: no-repeat;
  position: fixed;
  line-height: 100%;
  padding-top: 50px;
}

.logintext {
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

.logindata {
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 50%;
}

.tool {
  display: flex;
  justify-content: space-between;
  color: #606266;
}

.butt {
  margin-top: 10px;
  text-align: center;
}

.shou {
  cursor: pointer;
  color: #606266;
}
</style>